import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'styles/color_styles.dart';
import 'text_theme/default_text_theme.dart';

/* Light Theme
|--------------------------------------------------------------------------
| Theme Config - config/theme.dart
|-------------------------------------------------------------------------- */


ThemeData lightTheme(ColorStyles color) {
  TDTheme.needMultiTheme();
  var jsonString= '''
  {"default":{"ref":{"brandLightColor":"brandColor1","brandFocusColor":"brandColor2","brandDisabledColor":"brandColor3","brandHoverColor":"brandColor3","brandNormalColor":"brandColor4","brandActiveColor":"brandColor5","warningNormalColor":"warningColor5","warningHoverColor":"warningColor4","warningFocusColor":"warningColor2","warningActiveColor":"warningColor6","warningDisabledColor":"warningColor3","warningLightColor":"warningColor1","errorNormalColor":"errorColor6","errorHoverColor":"errorColor5","errorFocusColor":"errorColor2","errorActiveColor":"errorColor7","errorDisabledColor":"errorColor3","errorLightColor":"errorColor1","successNormalColor":"successColor5","successHoverColor":"successColor4","successFocusColor":"successColor2","successActiveColor":"successColor6","successDisabledColor":"successColor3","successLightColor":"successColor1","brandColorLightHover":"brandColor2","warningColorLightHover":"warningColor2","errorColorLightHover":"errorColor2","successColorLightHover":"successColor2"},"color":{"brandColor1":"#fff0eb","brandColor2":"#ffd8cd","brandColor3":"#ffb8a4","brandColor4":"#ff8362","brandColor5":"#e56f50","brandColor6":"#c25538","brandColor7":"#9f3b20","brandColor8":"#7f250b","brandColor9":"#621100","brandColor10":"#480a00","warningColor1":"#fef3e6","warningColor2":"#f9e0c7","warningColor3":"#f7c797","warningColor4":"#f2995f","warningColor5":"#ed7b2f","warningColor6":"#d35a21","warningColor7":"#ba431b","warningColor8":"#9e3610","warningColor9":"#842b0b","warningColor10":"#5a1907","errorColor1":"#fdecee","errorColor2":"#f9d7d9","errorColor3":"#f8b9be","errorColor4":"#f78d94","errorColor5":"#f36d78","errorColor6":"#e34d59","errorColor7":"#c9353f","errorColor8":"#b11f26","errorColor9":"#951114","errorColor10":"#680506","successColor1":"#e8f8f2","successColor2":"#bcebdc","successColor3":"#85dbbe","successColor4":"#48c79c","successColor5":"#00a870","successColor6":"#078d5c","successColor7":"#067945","successColor8":"#056334","successColor9":"#044f2a","successColor10":"#033017","grayColor1":"#f3f3f3","grayColor2":"#eee","grayColor3":"#e7e7e7","grayColor4":"#dcdcdc","grayColor5":"#c5c5c5","grayColor6":"#a6a6a6","grayColor7":"#8b8b8b","grayColor8":"#777","grayColor9":"#5e5e5e","grayColor10":"#4b4b4b","grayColor11":"#383838","grayColor12":"#2c2c2c","grayColor13":"#242424","grayColor14":"#181818"}}}
  ''';
  var _themeData = TDThemeData.fromJson('default', jsonString);

  return ThemeData(
    extensions: [_themeData!],
    useMaterial3: false,
    primaryColor: color.primaryContent,
    primaryColorLight: color.primaryAccent,
    focusColor: color.primaryContent,
    scaffoldBackgroundColor: color.background,

    // 去除水波纹
    splashColor: Colors.transparent,
    highlightColor: Colors.transparent,
    splashFactory: NoSplash.splashFactory,

    // hintColor: color.primaryAccent,
    dividerTheme: DividerThemeData(color: Colors.grey[100]),
    appBarTheme: AppBarTheme(
      surfaceTintColor: Colors.transparent,
      backgroundColor: Colors.transparent,
      titleTextStyle: defaultTextTheme.titleLarge?.copyWith(
        color: color.appBarPrimaryContent,
      ),
      centerTitle: true,
      iconTheme: IconThemeData(color: color.appBarPrimaryContent),
      elevation: 0.0,
      systemOverlayStyle: SystemUiOverlayStyle.dark,
    ),
    buttonTheme: ButtonThemeData(
      buttonColor: color.buttonPrimaryContent,
      colorScheme: ColorScheme.light(primary: color.buttonBackground),
    ),
    textButtonTheme: TextButtonThemeData(
      style: TextButton.styleFrom(foregroundColor: color.primaryContent),
    ),
    elevatedButtonTheme: ElevatedButtonThemeData(
      style: TextButton.styleFrom(
          foregroundColor: color.buttonPrimaryContent,
          backgroundColor: color.buttonBackground),
    ),
    bottomNavigationBarTheme: BottomNavigationBarThemeData(
      backgroundColor: color.bottomTabBarBackground,
      unselectedIconTheme:
          IconThemeData(color: color.bottomTabBarIconUnselected,size: 16),
      selectedIconTheme: IconThemeData(color: color.bottomTabBarIconSelected,size: 16),
      unselectedLabelStyle: TextStyle(color: color.bottomTabBarLabelUnselected),
      selectedLabelStyle: TextStyle(color: Color(0xFFff8362)),
      selectedItemColor: color.bottomTabBarLabelSelected,
    ),
    // textTheme: lightTheme,
    colorScheme: ColorScheme.light(
        background: color.background, primary: color.primaryAccent),
  );
}

/*
|--------------------------------------------------------------------------
| Light Text Theme
|--------------------------------------------------------------------------
*/

TextTheme _textTheme(ColorStyles colors) {
  Color primaryContent = colors.primaryContent;
  TextTheme textTheme = const TextTheme().apply(displayColor: primaryContent);
  return textTheme.copyWith(
      labelLarge: TextStyle(color: primaryContent.withOpacity(0.8)));
}
